<template>
  <div class="list-table">
    <div class="area-header">
      <span class="area-header-title">{{ $t('我的日程') }}</span>
    </div>
    <el-form ref="queryForm" :model="queryParams" :inline="true">
      <el-form-item :label="$t('开始日期')" prop="startTime">
        <el-date-picker
          v-model="dateStarts"
          type="datetimerange"
          align="right"
          :start-placeholder="$t('开始日期')"
          :end-placeholder="$t('结束日期')"
          :default-time="['00:00:00', '23:59:59']"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="queryHandle">{{ $t('搜索') }}</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">{{ $t('重置') }}</el-button>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          v-hasPermi="['oa:weekSchedule:edit']"
          type="primary"
          icon="el-icon-plus"
          size="mini"
          @click="addHandle"
        >{{ $t('新增') }}</el-button>
      </el-col>
    </el-row>

    <el-table v-loading="loading" :data="oaWeekScheduleList.slice((pageNum - 1) * pageSize, pageNum * pageSize)" border>
      <!-- <el-table-column :label="$t('序号')" type="index" align="center" show-overflow-tooltip width="50">
        <template slot-scope="scope">
          {{ (queryParams.pageNum - 1) * queryParams.pageSize + scope.$index + 1 }}
        </template>
      </el-table-column> -->
      <el-table-column :label="$t('日程描述')" align="center" prop="schedule" min-width="180" show-overflow-tooltip />
      <el-table-column :label="$t('开始时间')" align="center" prop="startTime" min-width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.startTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('结束时间')" align="center" prop="finishTime" min-width="180" show-overflow-tooltip>
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.finishTime, '{y}-{m}-{d} {h}:{i}:{s}') }}</span>
        </template>
      </el-table-column>
      <el-table-column :label="$t('完成状态')" align="center" prop="completion" :formatter="completionFormat" min-width="120" show-overflow-tooltip />

      <el-table-column :label="$t('操作')" align="center" class-name="small-padding fixed-width" width="200">
        <template slot-scope="scope">
          <el-button
            v-hasPermi="['oa:weekSchedule:edit']"
            size="small"
            type="text"
            icon="el-icon-edit"
            @click="updateHandle(scope.row)"
          >{{ $t('修改') }}</el-button>
          <el-button
            v-if="scope.row.showEdit"
            v-hasPermi="['oa:weekSchedule:remove']"
            size="small"
            type="text"
            icon="el-icon-delete"
            @click="deleteHandle(scope.row)"
          >{{ $t('删除') }}</el-button>
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total>0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 添加或修改本周日程对话框 -->
    <el-dialog :title="$t(title)" :visible.sync="formOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <oaWeekScheduleForm ref="oaWeekScheduleForm" />
    </el-dialog>

    <!-- 添加我的日程对话框 -->
    <el-dialog :title="$t(title)" :visible.sync="myformOpen" :close-on-click-modal="false" :lock-scroll="false" custom-class="dialogForm" append-to-body>
      <oaMyScheduleForm ref="oaMyScheduleForm" />
    </el-dialog>
  </div>
</template>

<script>
import { listOaWeekSchedule, delOaWeekSchedule } from '@/api/oa/weekSchedule/oaWeekSchedule'
import oaWeekScheduleForm from './oaWeekScheduleForm.vue'
import oaMyScheduleForm from '@/views/oa/mySchedule/oaMyScheduleForm'
export default {
    components: {
        oaWeekScheduleForm,
        oaMyScheduleForm
    },
  data() {
      return {
          // 遮罩层
          loading: true,
          // 总条数
          total: 0,
          // 本周日程表格数据
          oaWeekScheduleList: [],
          completionOptions: [],
          dateStarts: [],
          // 弹出层标题
          title: '',
          // 是否显示弹出层
          formOpen: false,
          myformOpen: false,
          // 查询参数
          queryParams: {
              scheduleId: undefined,
              startTime: undefined,
              finishTime: undefined,
              pageNum: 1,
              pageSize: 10
          },
           pageNum: 1,
           pageSize: 10,
          // 表单参数
          form: {},
          // 表单校验
          rules: {}
      }
  },
  created() {
    this.getDicts('completion_status').then(response => {
      this.completionOptions = response.data
    })
      this.getList()
  },
  methods: {
    /** 查询本周日程列表 */
    getList() {
        this.loading = true
        if (this.dateStarts != null && this.dateStarts.length > 1) {
          this.queryParams.startDate = this.dateStarts[0]
          this.queryParams.endDate = this.dateStarts[1]
        } else {
          this.queryParams.startDate = undefined
          this.queryParams.endDate = undefined
        }
        listOaWeekSchedule(this.queryParams).then(response => {
            this.oaWeekScheduleList = response.rows
            this.total = response.total
            this.loading = false
        })
    },
    completionFormat(row) {
      return this.selectDictLabel(this.completionOptions, row.completion)
    },
    // 表单重置
    reset() {
        this.form = {
            id: undefined,
            scheduleId: undefined,
            startTime: undefined,
            finishTime: undefined,
            travel: undefined,
            entourage: undefined,
            provinceRegistered: undefined,
            cityRegistered: undefined,
            completion: undefined,
            schedule: undefined,
            remark: undefined,
            createBy: undefined,
            updateBy: undefined,
            createTime: undefined,
            updateTime: undefined,
            delFlag: undefined
        }
        this.resetForm('form')
    },
    /** 搜索按钮操作 */
    queryHandle() {
        this.queryParams.pageNum = 1
        this.getList()
    },
    /** 重置按钮操作 */
    resetQuery() {
        this.resetForm('queryForm')
        this.dateStarts = []
        this.queryHandle()
    },
    /** 新增按钮操作 */
    addHandle() {
        this.myformOpen = true
        this.title = '我的日程'
        this.$nextTick(() => {
            this.$refs.oaMyScheduleForm.init(null)
        })
    },
    /** 修改按钮操作 */
    updateHandle(row) {
        this.formOpen = true
        this.title = '我的日程'
        this.$nextTick(() => {
            // 调用form页面的 init 方法初始化数据
            this.$refs.oaWeekScheduleForm.init(row)
        })
    },
    /** 删除按钮操作 */
    deleteHandle(row) {
        this.$confirm(this.$t('是否确认删除?'), this.$t('警告'), {
            confirmButtonText: this.$t('确定'),
            cancelButtonText: this.$t('取消'),
            type: 'warning'
        }).then(function() {
            return delOaWeekSchedule(row.id)
        }).then(() => {
            this.getList()
            this.msgSuccess(this.$t('删除成功'))
        }).catch(function() {
        })
    },
    handleSizeChange(val) {
      console.log(this.pageSize, this.pageNum)
      this.pageSize = val
    },
    handleCurrentChange(val) {
      console.log(this.pageSize, this.pageNum)
      this.pageNum = val
    },
    subList() {
        console.log(this.pageSize, this.pageNum)
    }
  }
}
</script>
